package mao.leetcode.others.leetcode90;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;


public class Solution {
    private List<List<Integer>>  res = new LinkedList<>();
    private List<Integer> tmp = new LinkedList<>() ;
    private int[] nums;
    private int length;

    public List<List<Integer>> subsetsWithDup(int[] nums) {
        this.nums = nums;
        this.length = nums.length;
        helper(0);
        return res;

    }

    public void helper(int idx){
        if(idx >= length) {
            res.add(new LinkedList<Integer>(tmp));
            return;
        }

        Set<Integer> set = new HashSet<>();
        helper(idx+1);
        for(int i = idx;i<length;i++){
            if(!set.contains(nums[i])){
                tmp.add(nums[i]);
                set.add(nums[i]);
                helper(i+1);
                tmp.remove(tmp.size()-1);

            }
        }
    }

    public static void main(String[] args) {
        int[] ints = {1,2,2};
        List<List<Integer>> lists = new Solution().subsetsWithDup(ints);
        System.out.println(lists);
    }
}
